<template>
  <div id="screening">
    <el-button type="primary" @click="dialogVisible = true" icon="el-icon-plus"
      >新建</el-button
    >
    <el-dialog title="可见人员" :visible.sync="dialogVisible" width="80%">
      <el-tabs type="card">
        <el-tab-pane label="主业单位">
          <div class="top">
            <span class="department">所属部门</span>
            <el-select
              v-model="trainValue"
              placeholder="Select"
              filterable
              clearable
            >
              <el-option
                v-for="item in business"
                :label="item.ORG_NAME"
                :key="item.SITEINFO_ID"
                :value="item.SITEINFO_ID"
              >
              </el-option>
            </el-select>
            <span class="department">人员名称</span>
            <el-input placeholder="请输入名称" v-model="trainInput"></el-input>
            <div class="query">
              <el-button type="primary" @click="trainQuery">查询</el-button>
            </div>
          </div>
          <hr />
          <div class="btn">
            <div class="btns1">
              <el-table
                :data="trainData"
                @selection-change="handleSelectionChange"
              >
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column label="待选择人员" prop="name">
                </el-table-column>
              </el-table>
              <el-pagination
                background
                small
                @size-change="sizeChangeA"
                @current-change="currentChangeA"
                :pager-count="5"
                :page-sizes="[7, 10, 20, 40]"
                :page-size="10"
                layout="total, sizes, prev, pager, next"
                :total="paginationA.totalRows"
              >
              </el-pagination>
            </div>
            <div class="btns2">
              <el-button
                type="primary"
                icon="el-icon-arrow-left"
                disabled
              ></el-button>
              <el-button
                type="primary"
                icon="el-icon-arrow-right"
                @click="trainRight"
                disabled
              ></el-button>
            </div>
            <div class="btns3">
              <el-table :data="altogether">
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column label="已选择人员" prop="name">
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-tab-pane>

        <el-tab-pane label="省管产业单位">
          <div class="top">
            <span class="department">所属部门</span>
            <el-select
              v-model="industryValue"
              placeholder="Select"
              filterable
              clearable
            >
              <el-option
                v-for="item in trainIndustry"
                :label="item.ORG_NAME"
                :key="item.SITEINFO_ID"
                :value="item.SITEINFO_ID"
              >
              </el-option>
            </el-select>
            <span class="department">人员名称</span>
            <el-input
              placeholder="请输入名称"
              v-model="industryInput"
            ></el-input>
            <div class="query">
              <el-button type="primary" @click="industryQuery">查询</el-button>
            </div>
          </div>
          <hr />
          <div class="btn">
            <div class="btns1">
              <el-table
                :data="industryData"
                @selection-change="handleSelectionIndustry"
              >
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column label="待选择人员" prop="name">
                </el-table-column>
              </el-table>
              <el-pagination
                background
                small
                @size-change="sizeChangeB"
                @current-change="currentChangeB"
                :pager-count="5"
                :page-sizes="[7, 10, 20, 40]"
                :page-size="10"
                layout="total, sizes, prev, pager, next"
                :total="paginationB.totalRows"
              >
              </el-pagination>
            </div>
            <div class="btns2">
              <el-button
                type="primary"
                icon="el-icon-arrow-left"
                disabled
              ></el-button>
              <el-button
                type="primary"
                icon="el-icon-arrow-right"
                @click="trainRight"
                disabled
              ></el-button>
            </div>
            <div class="btns3">
              <el-table :data="altogether">
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column label="已选择人员" prop="name">
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-tab-pane>

        <el-tab-pane label="外包单位">
          <div class="top">
            <span class="department">所属部门</span>
            <el-select
              v-model="outsourceValue"
              placeholder="Select"
              filterable
              clearable
            >
              <el-option
                v-for="item in trainOutsource"
                :label="item.ORG_NAME"
                :key="item.SITEINFO_ID"
                :value="item.SITEINFO_ID"
              >
              </el-option>
            </el-select>
            <span class="department">人员名称</span>
            <el-input
              placeholder="请输入名称"
              v-model="outsourceInput"
            ></el-input>
            <div class="query">
              <el-button type="primary" @click="outsourceQuery">查询</el-button>
            </div>
          </div>
          <hr />
          <div class="btn">
            <div class="btns1">
              <el-table
                :data="outsourceData"
                @selection-change="handleSelectionOutsource"
              >
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column label="待选择人员" prop="name">
                </el-table-column>
              </el-table>
              <el-pagination
                background
                small
                @size-change="sizeChangeC"
                @current-change="currentChangeC"
                :pager-count="5"
                :page-sizes="[7, 10, 20, 40]"
                :page-size="10"
                layout="total, sizes, prev, pager, next"
                :total="paginationC.totalRows"
              >
              </el-pagination>
            </div>
            <div class="btns2">
              <el-button
                type="primary"
                icon="el-icon-arrow-left"
                disabled
              ></el-button>
              <el-button
                type="primary"
                icon="el-icon-arrow-right"
                @click="trainRight"
                disabled
              ></el-button>
            </div>
            <div class="btns3">
              <el-table :data="altogether">
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column label="已选择人员" prop="name">
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { trainObtain, trainDepartment } from "@/business/api/train";

export default {
  name: "screening",
  data() {
    return {
      dialogVisible: false,

      trainInput: "",
      industryInput: "",
      outsourceInput: "",

      trainValue: "请选择",
      industryValue: "请选择",
      outsourceValue: "请选择",
      // 人员被选择后总数据
      altogether: [],
      screeningData: {
        // code: null,
        id: "",
        // microId: null,
        name: "筛选人员",
        // note: null,
        // ord: null,
        // state: 1,
      },

      // 主页人员
      // 所有人员数组
      trainData: [],
      // 人员被选择后数组
      multipleSelection: [],
      // 模糊查询后数组
      queryVague: [],
      // trainAlready: [],
      // 选择框数据
      business: [],

      // 省管产业单位
      // 获取人员
      industryData: [],
      // 人员被选择后
      industryChoice: [],
      // 模糊查询后
      industryVague: [],
      // 选择框
      trainIndustry: [],

      // 外包单位
      //获取人员
      outsourceData: [],
      // 人员被选择后
      outsourceChonice: [],
      // 模糊查询后
      outsourceVague: [],
      // 选择框的数据
      trainOutsource: [],

      // 分页
      paginationA: {
        pageSize: 10, // 每页显示条数
        totalRows: 0, //总条数
        pageNumber: 1, // 第几页
      },
      paginationB: {
        pageSize: 10, // 每页显示条数
        totalRows: 0, //总条数
        pageNumber: 1, // 第几页
      },
      paginationC: {
        pageSize: 10, // 每页显示条数
        totalRows: 0, //总条数
        pageNumber: 1, // 第几页
      },
    };
  },
  mounted() {
    // 获取人员
    this.getTrain();
    this.getIndustry();
    this.getOutsource();

    // 获取部门
    this.getDepartment();
  },
  methods: {
    // 当选择项发生变化时会触发该事件
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.sumData();
    },
    handleSelectionIndustry(val) {
      this.industryChoice = val;
      this.sumData();
    },
    handleSelectionOutsource(val) {
      this.outsourceChonice = val;
      this.sumData();
    },
    // 被选择人员总数据
    sumData() {
      this.altogether = this.multipleSelection
        .concat(this.industryChoice)
        .concat(this.outsourceChonice);
    },

    // 获取人员数据----------------------------------------------------------------------
    // 主业单位
    getTrain() {
      const pageSize = this.paginationA.pageSize;
      const pageNum = this.paginationA.pageNumber;
      trainObtain({
        pageNum,
        pageSize,
        workerNature: 1028001,
      }).then((res) => {
        this.trainData = res.info;
        this.paginationA.totalRows = res.totalCount;
      });
    },
    // 省管产业单位
    getIndustry() {
      const pageSize = this.paginationB.pageSize;
      const pageNum = this.paginationB.pageNumber;
      trainObtain({
        pageNum,
        pageSize,
        workerNature: 1028002,
      }).then((res) => {
        this.industryData = res.info;
        this.paginationB.totalRows = res.totalCount;
      });
    },
    // 外包单位
    getOutsource() {
      const pageSize = this.paginationC.pageSize;
      const pageNum = this.paginationC.pageNumber;
      trainObtain({
        pageNum,
        pageSize,
        workerNature: 1028003,
      }).then((res) => {
        this.outsourceData = res.info;
        this.paginationC.totalRows = res.totalCount;
      });
    },

    // 获取选项框部门 数据  ----------------------------------------------------------------
    // 主业单位
    getIndustryDepartment() {
      trainDepartment({
        orgNature: 1076001,
      }).then((res) => {
        this.business = res.info;
      });
    },
    // 省管产业单位
    getOutsourceDepartment() {
      trainDepartment({
        orgNature: 1076002,
      }).then((res) => {
        this.trainIndustry = res.info;
      });
    },
    // 获取外包公司
    getDepartment() {
      trainDepartment({
        orgNature: 1076003,
      }).then((res) => {
        this.trainOutsource = res.info;
      });
    },

    // 点击事件  暂时无用
    trainRight() {
      this.trainAlready = this.multipleSelection;
    },

    // 点击查询------------------------------------------------------------------------------
    // 主业单位
    trainQuery() {
      const name = this.trainInput;
      if (name == "") {
        return this.$message({
          showClose: true,
          message: "输入格式有误  请重新输入",
          type: "error",
        });
      } else {
        trainObtain({
          pageNum: 1,
          pageSize: 10,
          workerNature: 1028001,
          name,
        }).then((res) => {
          this.queryVague = res.info;
          this.trainData = this.queryVague;
          this.trainInput = "";
        });
      }
    },
    // 省管产业单位
    industryQuery() {
      const name = this.industryInput;
      if (name == "") {
        return this.$message({
          showClose: true,
          message: "输入格式有误  请重新输入",
          type: "error",
        });
      } else {
        trainObtain({
          pageNum: 1,
          pageSize: 10,
          workerNature: 1028002,
          name,
        }).then((res) => {
          this.industryVague = res.info;
          this.industryData = this.industryVague;
          this.industryInput = "";
        });
      }
    },
    // 外包人员
    outsourceQuery() {
      const name = this.outsourceInput;
      if (name == "") {
        return this.$message({
          showClose: true,
          message: "输入格式有误  请重新输入",
          type: "error",
        });
      } else {
        trainObtain({
          pageNum: 1,
          pageSize: 10,
          workerNature: 1028003,
          name,
        }).then((res) => {
          this.outsourceVague = res.info;
          this.outsourceData = this.outsourceVague;
          this.outsourceInput = "";
        });
      }
    },

    // 分页----------------------------------------------------
    // 主页单位
    currentChangeA(val) {
      //页码改变
      this.paginationA.pageNumber = val;
      this.getTrain();
    },
    sizeChangeA(val) {
      //切换每页显示条数
      this.paginationA.pageSize = val;
      this.getTrain();
    },
    // 省管产业单位
    currentChangeB(val) {
      //页码改变
      this.paginationB.pageNumber = val;
      this.getIndustry();
    },
    sizeChangeB(val) {
      //切换每页显示条数
      this.paginationB.pageSize = val;
      this.getIndustry();
    },
    // 外包单位
    currentChangeC(val) {
      //页码改变
      this.paginationC.pageNumber = val;
      this.getOutsource();
    },
    sizeChangeC(val) {
      //切换每页显示条数
      this.paginationC.pageSize = val;
      this.getOutsource();
    },
  },
};
</script>

<style lang="scss" scoped>
.top {
  display: flex;
  margin-bottom: 30px;
  .el-input {
    flex: 20%;
  }
  .el-select {
    flex: 30%;
  }
  .department {
    flex: 9%;
    height: 40px;
    line-height: 40px;
    margin: 0 10px;
  }
  .query {
    flex: 40%;
    text-align: left;
  }
  .query button {
    margin-left: 20px;
  }
}

.btn {
  display: flex;
  height: 260px;
  .btns1,
  .btns3 {
    flex: 40%;
    overflow: auto;
  }
  .btns2 {
    line-height: 260px;
    flex: 20%;
  }
}
</style>